package cn.demomaster.quickui.util;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;

import cn.demomaster.quicklogger.QdLog;

public class IntentUtil {
    public void startIntentUrl(Activity context, Intent intent) {
        if (context.getPackageManager().resolveActivity(intent, 0) == null) {
            String packagename = intent.getPackage();
            QdLog.e("packagename  ==>", packagename);
            if (packagename != null) {
                Uri uri = Uri.parse("market://search?q=pname:" + packagename);
                intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        } else {
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            try {
                context.startActivityIfNeeded(intent, -1);
            } catch (ActivityNotFoundException ex) {
                QdLog.e(ex);
            }
        }
    }
}
